package com.zjcloud.academic.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.zjcloud.common.annotation.Anonymous;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zjcloud.common.annotation.Log;
import com.zjcloud.common.core.controller.BaseController;
import com.zjcloud.common.core.domain.AjaxResult;
import com.zjcloud.common.enums.BusinessType;
import com.zjcloud.academic.domain.AcSemester;
import com.zjcloud.academic.service.IAcSemesterService;
import com.zjcloud.common.utils.poi.ExcelUtil;
import com.zjcloud.common.core.page.TableDataInfo;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 学期管理Controller
 * 
 * @author zjcloud
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/academic/semester")
public class AcSemesterController extends BaseController
{
    @Autowired
    private IAcSemesterService acSemesterService;

    /**
     * 查询学期管理列表
     */
    @Anonymous
    // @PreAuthorize("@ss.hasPermi('academic:semester:list')")
    @GetMapping("/list")
    public TableDataInfo list(AcSemester acSemester)
    {
        startPage();
        List<AcSemester> list = acSemesterService.selectAcSemesterList(acSemester);
        return getDataTable(list);
    }
    
    /**
     * 重定向到学期列表
     */
    @Anonymous
    @GetMapping("")
    public String redirectToList()
    {
        return "redirect:list";
    }

    /**
     * 导出学期管理列表
     */
    @PreAuthorize("@ss.hasPermi('academic:semester:export')")
    @Log(title = "学期管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AcSemester acSemester)
    {
        List<AcSemester> list = acSemesterService.selectAcSemesterList(acSemester);
        ExcelUtil<AcSemester> util = new ExcelUtil<AcSemester>(AcSemester.class);
        util.exportExcel(response, list, "学期管理数据");
    }

    /**
     * 获取学期管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('academic:semester:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(acSemesterService.selectAcSemesterById(id));
    }

    /**
     * 获取学期管理详细信息
     */
    @GetMapping(value = "/info/{id}")
    public AjaxResult getSemesterInfo(@PathVariable("id") Long id)
    {
        return success(acSemesterService.selectAcSemesterById(id));
    }

    /**
     * 获取当前学期
     */
    @PreAuthorize("@ss.hasPermi('academic:semester:query')")
    @GetMapping("/current")
    public AjaxResult getCurrentSemester()
    {
        return success(acSemesterService.selectCurrentSemester());
    }

    /**
     * 新增学期管理
     */
    @PreAuthorize("@ss.hasPermi('academic:semester:add')")
    @Log(title = "学期管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AcSemester acSemester)
    {
        return toAjax(acSemesterService.insertAcSemester(acSemester));
    }

    /**
     * 修改学期管理
     */
    @PreAuthorize("@ss.hasPermi('academic:semester:edit')")
    @Log(title = "学期管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AcSemester acSemester)
    {
        return toAjax(acSemesterService.updateAcSemester(acSemester));
    }

    /**
     * 设置当前学期
     */
    @PreAuthorize("@ss.hasPermi('academic:semester:edit')")
    @Log(title = "学期管理", businessType = BusinessType.UPDATE)
    @PutMapping("/setCurrent/{id}")
    public AjaxResult setCurrentSemester(@PathVariable Long id)
    {
        return toAjax(acSemesterService.setCurrentSemester(id));
    }

    /**
     * 删除学期管理
     */
    @PreAuthorize("@ss.hasPermi('academic:semester:remove')")
    @Log(title = "学期管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(acSemesterService.deleteAcSemesterByIds(ids));
    }
    
    /**
     * 获取学期下拉列表
     */
    @Anonymous
    @GetMapping("/options")
    public AjaxResult getOptions()
    {
        return success(acSemesterService.selectSemesterOptions());
    }
}